// pages/movie/movie.js
import Tx from "../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk";
import http from "../../utils/http";
var qqmapsdk = new Tx({
    key: 'AZLBZ-22X3K-7MKJ7-ANJ54-SH67F-2DFFN' // 必填
});
Page({

    /**
     * 页面的初始数据
     */
    data: {
        city: "",
        isActive: true,
        hotmovieList: [],
        comingmovieList: [],
        indicatorDots: false,
        vertical: false,
        autoplay: false,
        interval: 2000,
        duration: 500,
        isDay:false,
        currentIndex:'',
    },
    changeTap(e) {
        if (e) {
            this.setData({
                isActive: !this.data.isActive
            })
        }
    },
    click(e){
        console.log(e);
        this.setData({
            currentIndex:e.currentTarget.dataset.id
        })
        
    },
    queryMultipleNodes:function(){
        const query = wx.createSelectorQuery() 
        query.select(".c-desc").boundingClientRect()
        query.exec(res=>{
            console.log(res)
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    getLocation() {
        var _this = this;
        wx.getLocation({
            success(res) {
                console.log(res);
                qqmapsdk.reverseGeocoder({
                    location: `${res.latitude},${res.longitude}`,
                    success: function (res) {
                        console.log(res);
                        _this.setData({
                            city: res.result.ad_info.city
                        })
                    }
                });
            }
        })
    },
    getHotMovie() {
        var _this = this;
        http.get("/api/douban/movie/in_theaters")
            .then(res => {
                console.log(res)
                _this.setData({
                    hotmovieList: res.data.data.list
                });
                console.log(this.data.hotmovieList)
            })
    },
    getComingMovie() {
        var _this = this;
        http.get("/api/douban/movie/top250")
            .then(res => {
                console.log(res)
                _this.setData({
                    comingmovieList: res.data.data.list
                });
                console.log(this.data.comingmovieList)

            })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        this.getLocation();
        this.getHotMovie();
        this.getComingMovie();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})